@import '../theme/color.scss';

@mixin border-position-radius($position: left) {
  border-top-#{$position}-radius: 0;
  border-bottom-#{$position}-radius: 0;
}

.devui-form-controls input[type='text'],
.devui-form-controls input[type='password'],
[dTextInput] {
  width: 100%;
  height: 28px;
}

[dTextArea] {
  width: 100%;
}

.devui-form-controls textarea,
[dTextInput],
[dTextarea] {
  box-sizing: border-box;
  padding: 4px 10px;
  color: $dark-1;
  vertical-align: middle;
  border: 1px solid $gray-1;
  border-radius: 2px;
  outline: none;
  background-color: $bg-white;

  &:not([disabled]):not(.disabled):not(.devui-disabled):not(.error) {
    &:hover,
    &:hover:focus {
      border-color: $hwc-color-border-hover;
    }

    &:focus {
      border-color: $hwc-color-border-active;
    }
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover {
      cursor: not-allowed;
      background-color: $disabled-bg;
      border-color: $disabled-border;
      color: $disabled-content;
    }
  }
}

.devui-form-controls textarea,
[dTextarea] {
  width: 100%;
}

// input 样式
.devui-input-group {
  position: relative;
  display: table;
  border-collapse: separate;
}

.devui-input-group-addon {
  border: 1px solid $gray-1;
  border-radius: 2px;
  display: table-cell;
  padding: 0 10px;
  text-align: center;

  &:last-child {
    @include border-position-radius(left);

    border-left: 0;
  }

  &:first-child {
    @include border-position-radius(right);

    border-right: 0;
  }
}

.devui-input {
  outline: none;
  background-color: $bg-white;
  border: 1px solid $gray-1;
  border-radius: 2px;
  padding: 5px 10px;
  line-height: 16px; // 解决ie中文字不居中，由于height28px，有10px的padding和2px的border，剩余16px，使用其他的会使文字不居中
  font-size: 12px;
  color: $dark-1;
  width: 100%;
  display: block;
  cursor: text;
  height: 28px;

  &:hover,
  &:hover:focus {
    border-color: $hwc-color-border-hover;
  }

  &:focus {
    border-color: $hwc-color-border-active;
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover,
    &:focus,
    &:hover:focus {
      border-color: $disabled-border;
      color: $disabled-content;
      background-color: $disabled-bg;
      cursor: not-allowed;
    }
  }

  &::placeholder {
    color: $dark-3;
  }

  &.devui-search-in-dropdown {
    margin: 0;
    border: none;
    padding: 5px 26px 5px 10px;
    background-color: $hwc-drop-down-search;
    color: $dark-1;

    &:-ms-input-placeholder {
      color: $dark-3;
    }

    &:hover {
      background-color: $hwc-drop-down-search-hover;
    }
  }

  .devui-input-group > & {
    display: table-cell;
  }

  .devui-input-group > &:first-child {
    @include border-position-radius(right);
  }

  .devui-input-group > &:last-child {
    @include border-position-radius(left);
  }

  .devui-input-group > &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
}

.devui-input-lg {
  font-size: 16px;
  line-height: 20px; // 同devui-input
  height: 32px;
}

.devui-input-sm {
  font-size: 12px;
  line-height: 14px; // 同devui-input
  height: 26px;
}

// dropdown 公共样式
.devui-dropup,
.devui-dropdown {
  position: relative;
}

.devui-form-group {
  position: relative;
}

.devui-form-control {
  color: $dark-1;
  background-color: $bg-white;
  padding: 5px 10px;
  border: 1px solid $gray-1;
  display: block;
  width: 100%;
  height: 28px;
  border-radius: 2px;
  outline: 0;

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover,
    &:focus {
      border-color: $disabled-border;

      &,
      & > input {
        color: $disabled-content;
        background-color: $disabled-bg;
        cursor: not-allowed;
      }
    }
  }

  &:hover,
  &:hover:focus {
    border-color: $hwc-color-border-hover;
  }

  &:focus {
    border-color: $hwc-color-border-active;
  }
}

:not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
  > .devui-dropdown-origin {
    position: relative;
    z-index: 1;
  }

  > .devui-dropdown-origin:hover:not([disabled]):not(.disabled):not(.devui-disabled):not(:focus):not(.devui-dropdown-origin-open) {
    border-color: $hwc-color-border-hover;
  }

  > .devui-dropdown-origin:focus:not([disabled]):not(.disabled):not(.devui-disabled) {
    outline: none;
    border-color: $hwc-color-border-active;

    &:not(.devui-select-underlined-border):not(.devui-dropdown-no-border) {
      box-shadow: 0 2px 5px 0 $dark-1-boxshadow;
    }
  }

  > .devui-dropdown-origin.devui-dropdown-origin-open:not([disabled]):not(.disabled):not(.devui-disabled) {
    outline: none;
    border-color: $brand-1;
    border-radius: 2px 2px 0 0;

    &:not(.devui-select-underlined-border):not(.devui-dropdown-no-border) {
      box-shadow: 0 2px 5px 0 $dark-1-boxshadow;
    }
  }

  > .devui-dropdown-origin.devui-dropdown-origin-open:not(.devui-no-border):not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-dropdown-no-border) {
    z-index: 1052; // 为了让dividing边框覆盖cdk边框颜色

    & ~ .devui-form-control-feedback {
      z-index: 1052;
    }

    &.devui-dropdown-origin-bottom {
      border-bottom-color: $dividing;
      box-shadow: none;

      &::after {
        content: '';
        width: 100%;
        height: 1px;
        background-color: $dividing;
        position: absolute;
        z-index: 1001;
        left: 0;
        top: 100%;
      }
    }

    &.devui-dropdown-origin-top {
      border-top-color: $dividing;

      &:not(.devui-select-underlined-border) {
        box-shadow: 0 2px 5px 0 $dark-1-boxshadow;
      }

      &::after {
        content: '';
        width: 100%;
        height: 1px;
        background-color: $dividing;
        position: absolute;
        z-index: 1001;
        left: 0;
        top: -1px;
      }
    }
  }
}

.devui-dropdown-origin-wrapper {
  color: $dark-1;
  background-color: $bg-white;
  min-height: 28px;
  max-height: 52px;

  & > .devui-input,
  & > .devui-form-control {
    height: 26px;
  }

  &:not(.devui-select-underlined-border) {
    border: 1px solid $gray-1;
    border-radius: 2px;
  }

  .devui-form-control,
  .devui-form-control:hover,
  .devui-form-control:focus,
  .devui-form-control:focus:hover,
  .devui-input-group-addon,
  .devui-input-group-addon:hover,
  .devui-input-group-addon:focus,
  > .devui-dropdown-default,
  > .devui-dropdown-default:hover,
  > .devui-dropdown-default:active,
  > .devui-dropdown-default:focus {
    position: relative;
    z-index: 1001;
    border-color: transparent;
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    .devui-form-control,
    .devui-form-control:hover,
    .devui-form-control:focus,
    .devui-form-control:focus:hover,
    .devui-input-group-addon,
    > .devui-dropdown-default,
    > .devui-dropdown-default:hover,
    > .devui-dropdown-default:active,
    > .devui-dropdown-default:focus {
      background-color: $disabled-bg;
    }
  }

  &:not([disabled]):not(.disabled):not(.devui-disabled) {
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled),
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):hover,
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):focus,
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):focus:hover,
    .devui-input-group-addon,
    > .devui-dropdown-default,
    > .devui-dropdown-default:hover,
    > .devui-dropdown-default:active,
    > .devui-dropdown-default:focus {
      background-color: $bg-white;
    }
  }
}

// css选择器不可合并，否则css解析器总是会失败
input::-moz-placeholder {
  color: $dark-3;
}

input:-ms-input-placeholder {
  color: $dark-3;
}

input::-webkit-input-placeholder {
  color: $dark-3;
}

[dTextInput]:not([disabled]):not(.disabled):not(.devui-disabled).error,
[dTextarea]:not([disabled]):not(.disabled):not(.devui-disabled).error {
  border-color: $hwc-status-danger-border;
  background-color: $hwc-status-danger-background;
}
